#!/bin/bash
#yyl
#yyl@devnull
#内容需要删除时总是出现^H解决#在脚本的开头或结尾 参数 stty erase ^H stty erase ^?
stty erase ^?
#重装系统发上架专用脚本

#判断服务器型号
function menu(){
xinghao=`dmidecode |grep "Product Name"|awk '{print $4}'|sed -n '1p'`
s0=`echo ${xinghao:0:4} `
if [ $s0 = "R720" ]
then
   echo  "检测到当前服务器为R720/R720xd" 
   menu720
elif [ $s0 = "R730" ]
then
   echo  "检测到当前服务器为R730/R730xd" 
   menu730
elif [ $s0 = "R740" ]
then
   echo  "检测到当前服务器为R740/R740xd"
   menu740
elif [ $s0 = "R620" ]
then
   echo  "检测到当前服务器为R620"
   menu620
   elif [ $s0 = "R630" ]
then
   echo  "检测到当前服务器为R630"
   menu630
elif [ $s0 = "C632" ]
then
   echo  "检测到当前服务器为C6230"
   menu6230
elif [ $s0 = "C622" ]
then
   echo  "检测到当前服务器为C6220"
   menu6230   
   
else
   
   menu1
fi
}

#服务器R720/R720xd菜单
function menu720(){
cat << EOF
-------------------------------
|*****业务机(R720/R720XD)*****|
-------------------------------
`echo ' '`
========【重装系统发上架专用脚本】===========

|----------------------------------------------|
|      【1】安装常用工具包及压力测试软件       |
|----------------------------------------------|
|      【2】配置IPMI      【3】配置IP到网卡em1 |
|----------------------------------------------|
|      【4】全面检测(可自动升级内核和固件)     |
|----------------------------------------------|
|      【5】压力测试      【6】查内存报错      |
|----------------------------------------------|
|      【7】云机环境安装  【8】开启云机测试    |
|----------------------------------------------|
|      【S】关闭系统      【r】重启            |
|----------------------------------------------|
|      【q】退出                               |
================================================
`echo ' '`
EOF
read -p "请输入对应的数字：" num2
case $num2 in
  1)
  echo "安装常用工具包"
  tools
  ;;
  2)
  echo "配置IPMI"
  IPMI
  ;;
  3)
  echo "配置IP到网卡em1"
  IP
  ;;
  4)
  echo "全面检测 "
  testing
  test720
  ;;
  5)
  echo "压力测试 "
  yali
  ;;
  6)
  echo "查内存报错 "
  memcheck
  ;;
  7)
  echo "云机环境安装 "
  yunji
  ;;
  8)
  echo "开启云机测试 "
  yunjitest
  ;;
  s)
  echo "关闭系统 "
  init 0
  ;;
  r)
  echo "重启 "
  reboot
  ;;
  q)
  exit 0
  ;;
  *)
  menu
esac

}

#服务器R720/R720xd配置检测
function R720test(){
cat << EOF
`echo ' '`

=============================================
|      【1】一键升级固件及内核              |
|-------------------------------------------|
|      【q】退出   【r】返回上一级目录      |
=============================================
`echo ' '`
EOF
read -p "请输入对应的数字：" num5
case $num5 in
  1)
  echo "一键升级固件及内核"
  kernel
  R720iDrac
  H710p
  R720BIOS
  ;;
  r)
  menu
   ;;
  q)
  exit 0
  ;;
  *)
  menu
esac

}

#服务器R730/R730xd菜单
function menu730(){
cat << EOF
-------------------------------
|*****业务机(R730/R730XD)*****|
-------------------------------
`echo ' '`
==========【重装系统发上架专用脚本】============

|----------------------------------------------|
|      【1】安装常用工具包及压力测试软件       |
|----------------------------------------------|
|      【2】配置IPMI      【3】配置IP到网卡em1 |
|----------------------------------------------|
|      【4】全面检测(可自动升级内核和固件)     |
|----------------------------------------------|
|      【5】压力测试      【6】查内存报错      |
|----------------------------------------------|
|      【7】云机环境安装  【8】开启云机测试    |
|----------------------------------------------|
|      【S】关闭系统      【r】重启            |
|----------------------------------------------|
|      【q】退出                               |
================================================
`echo ' '`
EOF
read -p "请输入对应的数字：" num3
case $num3 in
  1)
  echo "安装常用工具包"
  tools
  ;;
  2)
  echo "配置IPMI"
  IPMI
  ;;
  3)
  echo "配置IP到网卡em1"
  IP
  ;;
  4)
  echo "全面检测 "
  testing
  test730
  ;;
  5)
  echo "压力测试 "
  yali
  ;;
  6)
  echo "查内存报错 "
  memcheck
  ;;
  7)
  echo "云机环境安装 "
  yunji
  ;;
  8)
  echo "开启云机测试 "
  yunjitest
  ;;
  s)
  echo "关闭系统 "
  init 0
  ;;
  r)
  echo "重启 "
  reboot
  ;;
  q)
  exit 0
  ;;
  *)
  menu
esac

}

#服务器R730/R730xd配置检测
function R730test(){
cat << EOF
`echo ' '`

=============================================
|      【1】一键升级固件及内核              |
|-------------------------------------------|
|      【q】退出   【r】返回上一级目录      |
=============================================
`echo ' '`
EOF
read -p "请输入对应的数字：" num6
case $num6 in
  1)
  echo "一键升级固件及内核"
  kernel
  R730iDrac
  R730RAID
  R730BIOS
  ;;
  r)
  menu
   ;;
  q)
  exit 0
  ;;
  *)
  menu
esac

}


#服务器R740/R740xd菜单
function menu740(){
cat << EOF
-------------------------------
|*****业务机(R740/R740XD)*****|
-------------------------------
`echo ' '`
==========【重装系统发上架专用脚本】============
|----------------------------------------------|
|      【1】安装常用工具包及压力测试软件       |
|----------------------------------------------|
|      【2】配置IPMI      【3】配置IP到网卡em1 |
|----------------------------------------------|
|      【4】全面检测(可自动升级内核和固件)     |
|----------------------------------------------|
|      【5】压力测试      【6】查内存报错      |
|----------------------------------------------|
|      【7】云机环境安装  【8】开启云机测试    |
|----------------------------------------------|
|      【S】关闭系统      【r】重启            |
|----------------------------------------------|
|      【q】退出                               |
================================================
`echo ' '`
EOF
read -p "请输入对应的数字：" num4
case $num4 in
  1)
  echo "安装常用工具包"
  tools
  ;;
  2)
  echo "配置IPMI"
  IPMI
  ;;
  3)
  echo "配置IP到网卡em1"
  IP
  ;;
  4)
  echo "全面检测 "
  testing
  test740raid
  ;;
  5)
  echo "压力测试 "
  yali
  ;;
  6)
  echo "查内存报错 "
  memcheck
  ;;
  7)
  echo "云机环境安装 "
  yunji
  ;;
  8)
  echo "开启云机测试 "
  yunjitest
  ;;
  s)
  echo "关闭系统 "
  init 0
  ;;
  r)
  echo "重启 "
  reboot
  ;;
  q)
  exit 0
  ;;
  *)
  menu
esac

}

#服务器R740/R740xd配置检测
function R740test1(){
cat << EOF
`echo ' '`

=============================================
|      【1】一键升级固件及内核              |
|-------------------------------------------|
|      【q】退出   【r】返回上一级目录      |
=============================================
`echo ' '`
EOF
read -p "请输入对应的数字：" num7
case $num7 in
  1)
  echo "一键升级固件"
  R740iDrac
  R730RAID
  R740BIOS
  ;;
  r)
  menu
   ;;
  q)
  exit 0
  ;;
  *)
  menu
esac

}


#服务器R740/R740xd配置检测
function R740test2(){
cat << EOF
`echo ' '`

=============================================
|      【1】一键升级固件及内核              |
|-------------------------------------------|
|      【q】退出   【r】返回上一级目录      |
=============================================
`echo ' '`
EOF
read -p "请输入对应的数字：" num7
case $num7 in
  1)
  echo "一键升级固件"
  R740iDrac
  R740RAID
  R740BIOS
  ;;
  r)
  menu
   ;;
  q)
  exit 0
  ;;
  *)
  menu
esac

}



#服务器R720/R720xd  BIOS固件升级    OK
 function R720BIOS(){
Bios720=`dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p'`
if [[ $Bios720 =~ "2.9.0" ]]
then
     echo "BIOS固件已经是2.9.0不用升级"
echo ' '
else
    wget -N http://192.168.2.182/bios/R720/BIOS_8P8WX_LN_2.9.0.BIN
    chmod a+x BIOS_8P8WX_LN_2.9.0.BIN
echo ' '
echo -e "BIOS升级中，升级过程会重启服务器"
echo ' '
expect <<EOF
spawn ./BIOS_8P8WX_LN_2.9.0.BIN
expect "*" { send "q\r" }
set timeout -1
expect "Y/N:" { send "y\r" }
set timeout -1
expect "Y/N:" { send "y\r" }
expect eof
EOF
fi
 }


#服务器R720/R720xd  RAID卡H710P mini固件升级
 function H710p(){
H710p='megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}''
if [[ $H710p =~ "21.3.1" ]]
then
     echo RAID卡H710P mini 固件号$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，无需要更新
echo ' '
else
echo RAID卡H710P mini 固件号不是最新的，需要更新
    wget -N http://192.168.2.182/bios/R720/SAS-RAID_Firmware_WDYTK_LN_21.3.5-0002_A09.BIN
    chmod a+x SAS-RAID_Firmware_WDYTK_LN_21.3.5-0002_A09.BIN   
echo ' '
echo -e "RAID卡固件升级中，升级过程会重启服务器"
echo ' '
expect <<EOF
spawn ./SAS-RAID_Firmware_WDYTK_LN_21.3.5-0002_A09.BIN
expect "*" { send "q\r" }
set timeout -1
expect "Y/N:" { send "y\r" }
set timeout -1
expect "Y/N:" { send "n\r" }
expect eof
EOF
fi
 }


#服务器R720/R720xd/R620  iDrac固件升级
 function R720iDrac(){
 idrac_results=`ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p'`
if [[ $idrac_results =~ "2.65" ]]
then
echo ' '
echo 当前iDrac固件号:$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')
echo '无需升级!!'
echo ' '
else
  echo "正在升级到2.65,升级过程比较久，不需要重启系统，请耐心等待！"

  wget -N http://192.168.2.182/bios/R720/iDRAC-with-Lifecycle-Controller_Firmware_0GHF4_LN_2.65.65.65_A00.BIN
  chmod a+x iDRAC-with-Lifecycle-Controller_Firmware_0GHF4_LN_2.65.65.65_A00.BIN
  expect <<EOF
  spawn ./iDRAC-with-Lifecycle-Controller_Firmware_0GHF4_LN_2.65.65.65_A00.BIN
  expect "*" { send "q\r" }
  set timeout -1
  expect "Y/N:" { send "y\r" }
  set timeout -1
  expect eof
EOF
fi
 }

#服务器R730/R730xd  BIOS固件升级      OK
 function R730BIOS(){
Bios730=`dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p'`
if [[ $Bios730 =~ "2.11.0" ]]
then
   echo  "BIOS固件已经是$(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p')，无需要更新" 
else
    wget -N http://192.168.2.182/bios/R730/BIOS_7YNRC_LN_2.11.0.BIN
    chmod a+x BIOS_7YNRC_LN_2.11.0.BIN  
echo ' '
echo -e "BIOS升级中，升级过程会重启服务器"
echo ' '
expect <<EOF
spawn ./BIOS_7YNRC_LN_2.11.0.BIN
expect "*" { send "q\r" }
set timeout -1
expect "Y/N:" { send "y\r" }
set timeout -1
expect "Y/N:" { send "y\r" }
expect eof
EOF
fi
 }


#服务器R730/R730xd  RAID卡H730P mini固件升级     OK
 function R730RAID(){
RAID730=`megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}'`
h730p=`echo ${RAID730:0:12} `
if [[ $h730p =~ "25.5.8.0001" ]]
then
   echo  "H730P mini RAID卡固件号$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，无需要更新" 
   else
echo "H730P mini RAID卡固件号不是最新的，需要更新25.5.6.0009"
    wget -N http://192.168.2.182/bios/R730/SAS-RAID_Firmware_WRF3Y_LN_25.5.8.0001_A16.BIN
    chmod a+x SAS-RAID_Firmware_WRF3Y_LN_25.5.8.0001_A16.BIN
echo ' '
echo -e "H730P mini RAID卡固件升级中，升级过程会重启服务器"
echo ' '
expect <<EOF
spawn ./SAS-RAID_Firmware_WRF3Y_LN_25.5.8.0001_A16.BIN
expect "*" { send "q\r" }
set timeout -1
expect "Y/N:" { send "y\r" }
set timeout -1
expect "Y/N:" { send "n\r" }
expect eof
EOF
fi
 }


#服务器R730/R730xd  iDrac固件升级    OK
 function R730iDrac(){
 idrac_results=`ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p'`
if [[ $idrac_results =~ "2.75" ]]
then
echo ' '
echo 当前iDrac固件号:$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')
echo '无需升级!!'
echo ' '
else
  echo "正在升级到2.75升级过程比较久，不需要重启系统，请耐心等待！"

  wget -N http://192.168.2.182/bios/R730/iDRAC-with-Lifecycle-Controller_Firmware_KRCXX_LN_2.75.75.75_A00.BIN
  chmod a+x iDRAC-with-Lifecycle-Controller_Firmware_KRCXX_LN_2.75.75.75_A00.BIN
  expect <<EOF
  spawn ./iDRAC-with-Lifecycle-Controller_Firmware_KRCXX_LN_2.75.75.75_A00.BIN
  expect "*" { send "q\r" }
  set timeout -1
  expect "Y/N:" { send "y\r" }
  set timeout -1
  expect eof
EOF
fi
 }
 
 #服务器R740/R740xd  BIOS固件升级
 function R740BIOS(){
  Bios740=`dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p'`
if [[ $Bios740 =~ "2.10.1" ]]
then
     echo "BIOS固件已经是2.10.1不用升级"
echo ' '
else
    wget -N http://192.168.2.182/bios/R740/BIOS_NVGR9_LN_2.10.0.BIN
    chmod a+x BIOS_NVGR9_LN_2.10.0.BIN  
echo ' '
echo -e "BIOS升级中，升级过程会重启服务器"
echo ' '
expect <<EOF
spawn ./BIOS_NVGR9_LN_2.10.0.BIN
expect "*" { send "q\r" }
set timeout -1
expect "Y/N:" { send "y\r" }
set timeout -1
expect "Y/N:" { send "y\r" }
expect eof
EOF
fi
 }


#服务器R740/R740xd  RAID卡H740P mini固件升级
 function R740RAID(){
  RAID740='megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}''
if [[ $RAID740 =~ "51.13.2-3714" ]]
then
     echo RAID卡固件号$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，无需要更新
echo ' '
else
echo RAID卡固件号$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')不是最新的，需要更新
    wget -N http://192.168.2.182/bios/R740/SAS-RAID_Firmware_26PXK_LN_51.13.2-3714_A14.BIN
    chmod a+x SAS-RAID_Firmware_26PXK_LN_51.13.2-3714_A14.BIN  
echo ' '
echo -e "RAID卡固件升级中，升级过程会重启服务器"
echo ' '
expect <<EOF
spawn ./SAS-RAID_Firmware_26PXK_LN_51.13.2-3714_A14.BIN
expect "*" { send "q\r" }
set timeout -1
expect "Y/N:" { send "y\r" }
set timeout -1
expect "Y/N:" { send "n\r" }
expect eof
EOF
fi
 }


#服务器R740/R740xd  iDrac固件升级
 function R740iDrac(){
 iDrac=`ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p'`
if [[ $iDrac =~ "4.40" ]]
then
echo iDrac固件号$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')，无需要更新
else
echo iDrac版本不是最新的，需要更新到4.22
  wget -N http://192.168.2.182/bios/R740/iDRAC-with-Lifecycle-Controller_Firmware_62GW1_LN_4.40.00.00_A00.BIN
  chmod a+x iDRAC-with-Lifecycle-Controller_Firmware_62GW1_LN_4.40.00.00_A00.BIN
  expect <<EOF
  spawn ./iDRAC-with-Lifecycle-Controller_Firmware_62GW1_LN_4.40.00.00_A00.BIN
  expect "*" { send "q\r" }
  set timeout -1
  expect "Y/N:" { send "y\r" }
  set timeout -1
  expect eof
EOF
fi
 }


#服务器配置检测
 function testing(){
 echo '======================全面检测========================'
echo 
echo ========================================
echo 1.获取时间: $(date)
echo ========================================
echo 2.服务器型号: $(dmidecode |grep "Product Name"|awk '{print $3,$4}'|sed -n '1p') "   " SN码: $(dmidecode -s system-serial-number)
echo ========================================
echo 3.BIOS版本号: $(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p') "   " iDrac固件号: $(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')
echo ========================================
echo 4.系统版本: $(cat /etc/redhat-release)
echo ========================================
echo 5.内核版本: $(uname -r  )
echo ========================================
echo 6.CPU型号: $(cat /proc/cpuinfo | grep name | cut -f2 -d: |sed -n '1p') "   " CPU核心数: $(cat /proc/cpuinfo | grep name | cut -f2 -d: |wc -l)
echo ========================================
echo 7.内存容量: $(cat /proc/meminfo | grep "MemTotal:" | awk '{print $2,$3}'|sed -n '1p';free -g | grep "Mem:" | awk '{print $2}') "GB" "   " 内存条数量:DDR4：$(dmidecode|grep -P -A8 "Memory\s+Device"|grep -E 'Memory Device|Size|Locator'|grep -v Range |grep 'GB' | wc -l) 条"   "DDR3:  $(dmidecode|grep -P -A8 "Memory\s+Device"|grep -E 'Memory Device|Size|Locator'|grep -v Range |grep 'MB' | wc -l)条
echo ========================================
echo 8.万兆网卡: $(lspci | grep Ethernet | grep 10-Gigabit | sed -n '1p' | awk '{print $4,$5,$6,$7}') "   " 网口数量: $(lspci | grep Ethernet | grep 10-Gigabit | wc -l)
echo 当前万兆模块状态:$(ip addr | grep 'p1:' | awk '{print $2,$9}' ) "   "$(ip addr | grep 'p2:' | awk '{print $2,$9}' ) 
echo ========================================
sda=`fdisk -l|grep "Disk /dev/sda"`
sdb=`fdisk -l|grep "Disk /dev/sdb"`
echo ========================================
echo 硬盘分区信息:磁盘sda: $(echo ${sda:14:9} "   "磁盘sdb:  ${sdb:14:10})
echo 硬盘数量: $(megacli -pdlist -a0 | grep -E "Slot|Firmware state|Enclosure Device ID|[Ee]rror|Predictive"|egrep "Error|Firmware|Slot"|grep "Number"|wc -l) 个
echo ========================================
echo 9.RAID卡型号: $(megacli -AdpAllInfo -aALL | grep "Product Name    : " | awk -F ':' '{print $2}') "    " RAID卡版本 $(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')
echo  RAID卡信息
raid10=`megacli -LDInfo -Lall -aALL|grep "RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0"`
if [[ $raid10 = "RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0" ]]
then
echo 创建raid 10
else
echo 
fi
raid0=`megacli -LDInfo -Lall -aALL|grep "RAID Level          : Primary-0, Secondary-0, RAID Level Qualifier-0"`
if [[ $raid0 = "RAID Level          : Primary-0, Secondary-0, RAID Level Qualifier-0" ]]
then
echo 创建raid 0 
else
echo 
fi
raid6=`megacli -LDInfo -Lall -aALL|grep "RAID Level          : Primary-6, Secondary-0, RAID Level Qualifier-3"`
if [[ $raid6 = "RAID Level          : Primary-6, Secondary-0, RAID Level Qualifier-3" ]]
then
echo 创建raid 6 
else
echo 
fi
raid1=`megacli -LDInfo -Lall -aALL|grep "RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0"`
if [[ $raid1 = "RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0" ]]
then
echo 创建raid 1 
else
echo 
fi
echo ========================================
echo 10.IP地址: $(cat /etc/sysconfig/network-scripts/ifcfg-em1 | grep "IPADDR="|awk -F '=' '{print $2}'|sed -n '1p')
echo 子网掩码: $(cat /etc/sysconfig/network-scripts/ifcfg-em1 | grep "NETMASK="|awk -F '=' '{print $2}'|sed -n '1p') 
echo 网关: $(cat /etc/sysconfig/network-scripts/ifcfg-em1 | grep "GATEWAY="|awk -F '=' '{print $2}'|sed -n '1p') 
echo ========================================
echo 11.IPMI管理IP: $(ipmitool lan print 1 |grep "IP Address              :" |awk '{print $4}'|sed -n '1p')
echo IPMI掩码: $(ipmitool lan print 1 |grep "Subnet Mask             : " |awk '{print $4}'|sed -n '1p')
echo IPMI网关: $(ipmitool lan print 1 |grep "Default Gateway IP      : " |awk '{print $5}'|sed -n '1p')
echo ========================================
echo

}


#R720服务器配置检测
function test720(){
   echo  "当前服务器为R720/R720XD" 
   `echo ' '`
echo -e "\033[32m ****************************************\033[0m"
echo -e "\033[32m ****************************************\033[0m"
Version1=`dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p'`
if [[ $Version1 =~ "2.9.0" ]]
then
echo 当前BIOS版本是$(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p')，无需要更新 
else
echo -e "\033[32m 当前BIOS版本是$(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p')，需要更新到2.9.0 \033[0m"
fi

iDrac1=`ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p'`
if [[ $iDrac1 =~ "2.65" ]]
then
echo 当前iDrac版本是$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')，无需要更新 
else
echo -e "\033[32m 当前iDrac版本是$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')，需要更新到2.65 \033[0m"
fi

RAID1=`megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}'`
if [[ $RAID1 =~ "21.3.5" ]]
then
echo 当前RAID卡固件号$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，无需要更新 
else
echo -e "\033[32m当前RAID卡固件号$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，需要更新到21.3.5 \033[0m"
fi

uname1=`uname -r`
if [[ $uname1 =~ "4.4.229-1.el7.elrepo.x86_64" ]]
then
echo 当前内核是$(uname -r)，无需要更新 
else
echo -e "\033[32m 内核版本没有更新的，需要更新到4.4.229 \033[0m"
echo '==========================='
fi
echo -e "\033[32m ****************************************\033[0m"
echo -e "\033[32m ****************************************\033[0m"
R720test
}

#R730服务器配置检测
function test730(){
   echo  "当前服务器为R730/R730XD" 
   echo -e "\033[32m ****************************************\033[0m"
echo -e "\033[32m ****************************************\033[0m"
Version2=`dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p'`
if [[ $Version2 =~ "2.11.0" ]]
then
echo 当前BIOS版本是$(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p')，无需要更新
else
echo -e "\033[32m 当前BIOS版本是$(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p')，需要更新到2.11.0 \033[0m"
fi

iDrac2=`ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p'`
if [[ $iDrac2 =~ "2.75" ]]
then
echo 当前iDrac版本是$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')，无需要更新
else
echo -e "\033[32m 当前iDrac版本是$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')，需要更新到2.75\033[0m"
fi

RAID2=`megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}'`
if [[ $RAID2 =~ "25.5.6.0009" ]]
then
echo 当前RAID卡固件号是$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，无需要更新
else
echo -e "\033[32m 当前RAID卡固件号是$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，需要更新到25.5.6.0009\033[0m"
fi

uname2=`uname -r`
if [[ $uname2 =~ "4.4.229-1.el7.elrepo.x86_64" ]]
then
echo 当前内核是$(uname -r)，无需要更新
else
echo -e "\033[32m 内核版本没有更新的，需要更新到4.4.229 \033[0m"
echo '==========================='
fi
echo -e "\033[32m ****************************************\033[0m"
echo -e "\033[32m ****************************************\033[0m"
R730test
 }  
  
#R740服务器配置检测1
function test740_1(){  
echo  "当前服务器为R740/R740XD" 
echo -e "\033[32m ****************************************\033[0m"
echo -e "\033[32m ****************************************\033[0m"
Version4=`dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p'`
if [[ $Version4 =~ "2.10.1" ]]
then
echo 当前BIOS版本是$(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p')，无需要更新
else
echo -e "\033[32m 当前BIOS版本是$(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p')，需要更新到2.10.1\033[0m"
fi

iDrac4=`ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p'`
if [[ $iDrac2 =~ "4.40" ]]
then
echo 当前iDrac版本是$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')，无需要更新
else
echo -e "\033[32m  当前iDrac版本是$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')，需要更新到4.40\033[0m"
fi

RAID4=`megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}'`
if [[ $RAID4 =~ "25.5.6.0009" ]]
then
echo 当前RAID卡固件号是$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，无需要更新
else
echo -e "\033[32m  当前RAID卡固件号是$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，需要更新到25.5.6.0009 \033[0m"
fi
echo -e "\033[32m ****************************************\033[0m"
echo -e "\033[32m ****************************************\033[0m"
R740test1	
}


#R740服务器配置检测2
function test740_2(){  
echo  "当前服务器为R740/R740XD" 
echo -e "\033[32m ****************************************\033[0m"
echo -e "\033[32m ****************************************\033[0m"
Version3=`dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p'`
if [[ $Version3 =~ "2.10.1" ]]
then
echo 当前BIOS版本是$(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p')，无需要更新
else
echo -e "\033[32m 当前BIOS版本是$(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p')，需要更新到2.10.1 \033[0m"
fi

iDrac3=`ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p'`
if [[ $iDrac3 =~ "4.40" ]]
then
echo 当前iDrac版本是$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')，无需要更新
else
echo -e "\033[32m 当前iDrac版本是$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')，需要更新到4.22 \033[0m"
fi

RAID3=`megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}'`
if [[ $RAID3 =~ "50.9.4" ]]
then
echo 当前RAID卡固件号是$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，无需要更新
else
echo -e "\033[32m 当前RAID卡固件号是$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，需要更新到50.9.4 \033[0m"
fi
echo -e "\033[32m ****************************************\033[0m"
echo -e "\033[32m ****************************************\033[0m"
R740test2	
}


#R740服务器阵列卡检测
function test740raid(){
 echo  "当前服务器为R740/R740XD"
RAIDxh=`megacli -AdpAllInfo -aALL | grep "Product Name    : " | awk -F ':' '{print $2}'`
if [[ $RAIDxh =~ "PERC H740P Mini " ]]
then
echo 当前RAID卡是 $(megacli -AdpAllInfo -aALL | grep "Product Name    : " | awk -F ':' '{print $2}')
test740_2
else
当前RAID卡是 $(megacli -AdpAllInfo -aALL | grep "Product Name    : " | awk -F ':' '{print $2}')
test740_1
fi
}


#内核升级
function kernel(){
uname1=`uname -r`
uname0=`echo ${uname1:0:7} `
#if [ $uname0 = "4.4.229" ]
if [[ $uname0 =~ "4.4.229" ]]
then
   echo  "内核是$(uname -r)，无需要更新" 
   else
echo 内核版本没有更新的，需要更新到4.4.229
wget http://192.168.2.182/bios/kernel-lt-4.4.229-1.el7.elrepo.x86_64.rpm
wget http://192.168.2.182/bios/kernel-lt-devel-4.4.229-1.el7.elrepo.x86_64.rpm
yum localinstall kernel-lt-* -y
sed -i 's\saved\0\g' /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
fi
}

#配置IP到网卡em1 
function IP(){
echo '======================配置IP到网卡em1========================'
read -p "输入IP地址：(如192.168.2.88)"  IPADDR
read -p "输入网关：(如192.168.2.1 )"  gateway
read -p "输入掩码：(如255.255.255.0 )"  netmask
echo  IP配置中，请稍等 

sed -i "/IPADDR=/d" /etc/sysconfig/network-scripts/ifcfg-em1
sed -i "/NETMASK=/d" /etc/sysconfig/network-scripts/ifcfg-em1
sed -i "/GATEWAY=/d" /etc/sysconfig/network-scripts/ifcfg-em1

echo IPADDR=${IPADDR} >>  /etc/sysconfig/network-scripts/ifcfg-em1 
echo NETMASK=${netmask} >>  /etc/sysconfig/network-scripts/ifcfg-em1 
echo GATEWAY=${gateway} >>  /etc/sysconfig/network-scripts/ifcfg-em1
echo 
echo   
echo  IP配置完成打印IP信息 
echo '======================================================'
echo IP地址: $(cat /etc/sysconfig/network-scripts/ifcfg-em1 | grep "IPADDR="|awk -F '=' '{print $2}'|sed -n '1p')  
echo 子网掩码: $(cat /etc/sysconfig/network-scripts/ifcfg-em1 | grep "NETMASK="|awk -F '=' '{print $2}'|sed -n '1p')  
echo 网关: $(cat /etc/sysconfig/network-scripts/ifcfg-em1 | grep "GATEWAY="|awk -F '=' '{print $2}'|sed -n '1p')  
echo '======================================================'
 menu
}


#配置IPMI 
function IPMI(){
echo '======================IPMI设置========================'
read -p "请输入IP："  ipaddr
ipmitool lan set 1 ipsrc static
   		ipmitool lan set 1 ipaddr ${ipaddr}
   		read -p "请输入掩码："  netmask
   		ipmitool lan set 1 netmask ${netmask}
   		read -p "请输入网关："  defgw
   		ipmitool lan set 1 defgw ipaddr ${defgw}
   		ipmitool lan set 1 access on
   		ipmitool user set name 2 root
   		ipmitool user enable 2
   		ipmitool user set password 2 calvin
      echo ' '
    	echo '====================当前IPMI信息======================'
  		echo IPMI管理IP: $(ipmitool lan print 1 |grep "IP Address              :" |awk '{print $4}'|sed -n '1p')
  		echo IPMI掩码: $(ipmitool lan print 1 |grep "Subnet Mask             : " |awk '{print $4}'|sed -n '1p')
  		echo IPMI网关: $(ipmitool lan print 1 |grep "Default Gateway IP      : " |awk '{print $5}'|sed -n '1p')
  		echo -e "账号：root"
  		echo -e "密码：calvin"
  		echo '======================================================'
		menu
}

#常规工具包安装 
function tools(){
echo '关闭SELINUX'
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
echo '设置交换空间'
swappiness=`cat /etc/sysctl.conf | grep "vm.swappiness = 0"`
if [[ $swappiness =~ "vm.swappiness = 0" ]]
then
echo 交换空间已设置，无需设置
else
echo "vm.swappiness = 0" >> /etc/sysctl.conf
sysctl -p
fi
echo '安装常用工具包'
yum -y install iotop screen sysstat ipmitool gcc wget rdate expect  pciutils
rdate -s time.nist.gov
echo '安装压力测试工具包'

mkdir -p /home/tools
cd /home/tools
wget -P /home/tools/ http://192.168.2.182/yali/MegaCli8.02.21.tar.gz
wget -P /home/tools/ http://192.168.2.182/yali/cpuburn-1.0-amd64.tar.gz
wget -P /home/tools/ http://192.168.2.182/yali/memtester-4.2.2.tar.gz
wget -P /data/ http://192.168.2.182/yali/iotest.py
tar -zxf /home/tools/MegaCli8.02.21.tar.gz
cd /home/tools/MegaCli8.02.21
rpm -ivh /home/tools/MegaCli8.02.21/Lib_Utils-1.00-09.noarch.rpm > /dev/null
rpm -ivh /home/tools/MegaCli8.02.21/MegaCli-8.02.21-1.noarch.rpm > /dev/null
ln -sf /opt/MegaRAID/MegaCli/MegaCli64 /bin/megacli
megacli -LDSetProp WB -Lall -aall > /dev/null
megacli -LDSetProp CachedBadBBU -Lall -aall > /dev/null
cd /home/tools
tar -zxvf /home/tools/cpuburn-1.0-amd64.tar.gz
tar -zxvf /home/tools/memtester-4.2.2.tar.gz
cd /home/tools/memtester-4.2.2
make
make install
cd
wget -N http://192.168.2.182/yali/mem.sh
echo '压力测试工具安装完成'

echo '======================================================'
menu
}


# 开启压力测试
function yali(){

free=`free -g | grep "Mem" | awk '{print $2}'`
free1=$[free-22]G

screen -dmS cpu
screen -x -S cpu -p 0 -X stuff "cd /home/tools/cpuburn;./cpuburn\n"

screen -dmS mem
screen -x -S mem -p 0 -X stuff "memtester $free1 1\n"

screen -dmS io
screen -x -S io -p 0 -X stuff "cd /data/;python iotest.py\n"
echo ' '
echo '======压力测试窗口======'
screen -ls
echo -e "\033[32m 正在进行压力测试，请勿关机！\033[0m"

 menu
}


#查内存报错 
function memcheck(){
cd 
sh mem.sh
menu
} 

#云机环境安装 
function yunji(){
echo "关闭selinux "
sed -i "s@SELINUX=\(.*\)@SELINUX=disabled@g"  /etc/selinux/config
setenforce 0
dns1=1.1.1.1
dns2=2.2.2.2

#echo "安装ntp"
#yum install -y ntp
#timedatectl set-timezone Asia/Shanghai
#ntpdate time.apple.com
#hwclock -w
echo "同步时间......"
#crontab -l|grep "*/10 * * * * /usr/sbin/ntpdate pool.ntp.org | logger -t NTP"
yum install -y chrony
systemctl start chronyd
while [ $? -ne 0 ]
do
#yum install -y ntpdate
yum install -y expect
yum install -y rsync
timedatectl set-timezone Asia/Shanghai
ntpdate pool.ntp.org
hwclock -w
touch tempx
crontab tempx
rm -f tempx
crontab -l >/tmp/crontab.bak
echo "*/10 * * * * /usr/sbin/ntpdate pool.ntp.org | logger -t NTP" >> /tmp/crontab.bak
crontab /tmp/crontab.bak
done

yum install firewalld -y
systemctl start firewalld
yum install -y expect

yum install tcpdump -y

yum install iptraf -y

yum install ipmitool -y



yum install screen -y

yum install rsync -y

yum install fabric -y

chmod a+x /etc/rc.d/rc.local

echo "更新"
#2018-12-30 edit
#yum -x 'kernel*'  update -y



mkdir -p ~/.pip
touch ~/.pip/pip.conf

echo [global]  >> ~/.pip/pip.conf
echo trusted-host=pypi.douban.com   >> ~/.pip/pip.conf
echo index-url=http://pypi.douban.com/simple >> ~/.pip/pip.conf
yum install -y wget
yum install -y net-tools
yum install -y sysstat
yum install -y rdate



echo "正在安装api 依赖包........"
yum install -y yum-fastestmirror epel-release
yum install -y gcc gcc-c++ make python-devel zeromq-devel
yum install -y python-pip
pip install --upgrade pip
pip install setuptools==0.9.8
pip install tornado==4.5.2
pip install gevent==1.2.2
pip install fabric==1.14.0
pip install pyzmq msgpack-python zerorpc paramiko

#yum install -y centos-release-qemu-ev


echo "正在安装虚拟化...."
yum install -y @virt* dejavu-lgc-* xorg-x11-xauth tigervnc libguestfs-tools libguestfs-winsupport python-libguestfs policycoreutils-python
yum install -y   libvirt  bridge-utils virt-manager  virt-viewer virt-v2v virt-install libguestfs-xfs
#yum install -y qemu-kvm-tools qemu-img kvm

yum install tcping -y

echo "正在安装agent 依赖包........"
yum install -y gcc gcc-c++ make python-devel epel-release zeromq-devel libvirt-devel libxslt-devel
yum install -y python-pip
pip install --upgrade pip
pip install pyzmq msgpack-python gevent zerorpc uuid greenlet zmq libvirt-python  stevedore lxml requests
pip install pexpect==3.0
#pip install paramiko==1.16.0

echo "关闭NetworkManager"
systemctl stop NetworkManager
systemctl disable NetworkManager

echo "启动libvirtd...."
systemctl start libvirtd
systemctl enable libvirtd

#echo "设置防火墙......"
#yum install firewalld -y
#systemctl start firewalld
#firewall-cmd --permanent --add-port=8081/tcp
#firewall-cmd --permanent --add-port=8866/tcp
#firewall-cmd --permanent --add-port=16509/tcp
##firewall-cmd --permanent --add-port=50022/tcp
#firewall-cmd --permanent --add-icmp-block=echo-request
#firewall-cmd --permanent --add-icmp-block=echo-reply
##firewall-cmd --permanent --add-port=5900-6900/tcp
##firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 -s 121.201.54.129 -p tcp -m state --state NEW -m tcp --dport 5900:6900 -j ACCEPT
##firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 -s 121.201.54.130 -p tcp -m state --state NEW -m tcp --dport 5900:6900 -j ACCEPT
#firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="121.201.54.157" port protocol="tcp" port="50022" accept"
#firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="42.51.38.14" port protocol="tcp" port="50022" accept"
#firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.230.0/24" port protocol="tcp" port="50022" accept"
#firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="114.118.3.75" port protocol="tcp" port="50022" accept"
#firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="117.48.234.190" port protocol="tcp" port="50022" accept"
#firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="121.201.84.121" port protocol="tcp" port="50022" accept"
#firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="121.201.54.129" port protocol="tcp" port="50022" accept"
#firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="42.51.44.196" port protocol="tcp" port="50022" accept"
#firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="121.201.54.130" port protocol="tcp" port="5900-6900" accept"
#firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="121.201.54.129" port protocol="tcp" port="5900-6900" accept"
#firewall-cmd --reload




echo "设置防火墙......"

sleep 5



firewall-cmd --zone=public --add-port={8081/tcp,8866/tcp} --permanent
firewall-cmd --zone=public --add-icmp-block=echo-request --permanent
firewall-cmd --zone=public --add-icmp-block=echo-reply --permanent
firewall-cmd --reload


mkdir /home/tools



echo "下载api agent"
wget -P /home/tools/  http://117.48.234.190:4000/kvm-agent.1.5.xnbd.tar.gz
tar -zxvf /home/tools/kvm-agent.1.5.xnbd.tar.gz -C /home/tools/

cd  /home/tools/kvm-agent.1.5.xnbd/yhz-kvm-agent/
python setup.py install
cd /home/tools/kvm-agent.1.5.xnbd/yhz-kvm-api/
python setup.py install
sed -i "s@rpc_port = \(.*\)@rpc_port = 8081@g"  /etc/yhz-kvm-agent/agent.conf
sed -i "s@port = \(.*\)@port = 8080@g"  /etc/yhz-kvm-api/api.conf

echo "修改Windows dns"
sed -i "s@dns1 =\(.*\)@dns1 = \'$dns1\'@g"  /usr/lib/python2.7/site-packages/yhz_kvm_agent-1.0.0-py2.7.egg/agent/nbd/nbd.py
sed -i "s@dns2 =\(.*\)@dns2 = \'$dns2\'@g"  /usr/lib/python2.7/site-packages/yhz_kvm_agent-1.0.0-py2.7.egg/agent/nbd/nbd.py

echo "设置目录....."
cd /data
if [ $? -ne 0 ];then
    echo "创建/data......."
    mkdir /home/data
    ln -s /home/data /data
    cd /data
fi
mkdir -p /data/vmfs
chmod -R 777 /data/vmfs
virsh pool-define-as vmdisk --type dir --target /data/vmfs
virsh pool-build vmdisk
virsh pool-autostart vmdisk
virsh pool-start vmdisk
mkdir -p /data/image/tras
mkdir /data/kvm
mkdir /data/script

echo "下载script"
wget -P /data/script http://117.48.234.190:4000/script.tar.gz
tar -xzvf /data/script/script.tar.gz -C /data/script
echo "修改Linux dns"
sed -i "s@202.96.128.86@$dns1@g" /data/script/centos.sh
sed -i "s@202.96.134.133@$dns2@g" /data/script/centos.sh

echo "启动api agent"
kvm-api stop
kvm-agent stop
kvm-api start
kvm-agent start

echo "修改/etc/sysconfig/libvirtd........"
sed -i "s@#remote_display_port_min = 5900@remote_display_port_min = 5901@g" /etc/libvirt/qemu.conf
sed -i "s@#LIBVIRTD_ARGS=\(.*\)@LIBVIRTD_ARGS="\"--listen\""@g"  /etc/sysconfig/libvirtd
echo "修改/etc/libvirt/libvirtd.conf"
sed -i "s@#listen_tls = 0@listen_tls = "0"@g"  /etc/libvirt/libvirtd.conf
sed -i "s@#listen_tcp = 1@listen_tcp = "1"@g"  /etc/libvirt/libvirtd.conf
sed -i "s@tls_port = \"16514\"@tls_port = "0"@g"  /etc/libvirt/libvirtd.conf
sed -i "s@#tcp_port = \"16509\"@tcp_port = "\"16509\""@g"  /etc/libvirt/libvirtd.conf
sed -i "s@#listen_addr = \(.*\)@listen_addr = "\"0.0.0.0\""@g"  /etc/libvirt/libvirtd.conf
sed -i "s@#auth_tcp = \(.*\)@auth_tcp = "\"sasl\""@g"  /etc/libvirt/libvirtd.conf

echo "重启libvirtd........"
systemctl restart libvirtd
systemctl enable  libvirtd
echo "yum install ntfs*..........."
yum install -y vconfig
yum install -y ntfs*

echo "下载监控........"
wget -P /home/  http://117.48.234.190:4000/monitor.tar.gz
tar -zxvf /home/monitor.tar.gz   -C /home/
cp /home/monitor/monitor/*   /home/monitor/





echo '下载manage_ip.py,下载nbd-kernel'
cd /home/tools

wget http://www.updateweb.cn/softwares/paping_1.5.5_x86-64_linux.tar.gz
tar zxvf paping_1.5.5_x86-64_64_linux.tar.gz
cp paping /usr/bin


wget  http://117.48.234.190:4000/manageIp.py
#wget  -c http://117.48.234.190:4000/kernel-3.10.0-327.el7.src.rpm
#wget  -c http://117.48.234.190:4000/qemu-2.10.1-1.el7.centos.x86_64.rpm


#echo '安装nbd..................'
#yum install -y kernel-devel kernel-headers
#rpm -ihv /home/tools/kernel-3.10.0-327.el7.src.rpm
#cd ~/rpmbuild/SOURCES
#tar Jxvf linux-3.10.0-327.el7.tar.xz -C /usr/src/kernels/
#cd /usr/src/kernels/
#mv $(uname -r) $(uname -r)-old
#if [ $? -ne 0 ]
#then
#    ls /usr/src/kernels/
#    read -p "Please input kernel name:" kernel
#    mv $kernel $(uname -r)
#    mv $(uname -r) $(uname -r)-old
#fi
#mv linux-3.10.0-327.el7 $(uname -r)
#cd $(uname -r)
#make mrproper
#cp ../$(uname -r)-old/Module.symvers ./
#cp /boot/config-$(uname -r) ./.config
#wget -O .config http://117.48.234.190:4000/config.old.centos72
#make oldconfig
#make prepare
#make scripts
#make CONFIG_BLK_DEV_NBD=m M=drivers/block
#cp drivers/block/nbd.ko /lib/modules/$(uname -r)/kernel/drivers/block/
#depmod -a
#modprobe nbd max_part=8


#echo '安装l3 cache'
#cd /home/tools
#rpm -ivh qemu-2.10.1-1.el7.centos.x86_64.rpm
#mv /usr/libexec/qemu-kvm /usr/libexec/qemu-kvm-1.5.3
#ln -s /usr/local/qemu-2.10.1/bin/qemu-system-x86_64 /usr/libexec/qemu-kvm
#systemctl restart libvirtd

#echo '安装l3 cache'
cd /home/tools
wget -N -c http://117.48.234.190:4000/qemu-4.0.0-1.el7.x86_64.rpm
rpm -ivh qemu-4.0.0-1.el7.x86_64.rpm
qver=`/usr/libexec/qemu-kvm --version | grep version | awk '{print $4}' | awk -F"[()]" '{print $1}'`
mv /usr/libexec/qemu-kvm /usr/libexec/qemu-kvm-$qver
ln -s /usr/local/qemu-4.0.0/bin/qemu-system-x86_64 /usr/libexec/qemu-kvm
mv /usr/bin/qemu-img /usr/bin/qemu-img-$qver
ln -s /usr/local/qemu-4.0.0/bin/qemu-img /usr/bin/qemu-img
mv /usr/bin/qemu-io /usr/bin/qemu-io-$qver
ln -s /usr/local/qemu-4.0.0/bin/qemu-io /usr/bin/qemu-io
mv /usr/bin/qemu-nbd /usr/bin/qemu-nbd-$qver
ln -s /usr/local/qemu-4.0.0/bin/qemu-nbd /usr/bin/qemu-nbd
systemctl stop libvirtd
systemctl start libvirtd

yum install kvm -y
yum -y install nginx  #方便做备案打包环境

#设置内网
cd /home/tools/

wget   http://117.48.234.190:4000/openvswitch-2.3.0-1.x86_64.rpm > /dev/null
rpm -ivh openvswitch-2.3.0-1.x86_64.rpm > /dev/null
systemctl start openvswitch
systemctl enable openvswitch
brctl addbr br1000
ip link set dev br1000 up
cat <<END> /etc/sysconfig/network-scripts/ifcfg-br1000
TYPE=Bridge
BOOTPROTO=none
DEFROUTE=yes
DEVICE=br1000
ONBOOT=yes
END
ovs-vsctl add-br br-int
ip link set dev br-int up
ip link add br1000-int type veth peer name int-br1000
brctl addif br1000 br1000-int;ovs-vsctl add-port br-int int-br1000
ip link set dev br1000-int up;ip link set dev int-br1000 up
cat <<END> /etc/sysconfig/network-scripts/ifcfg-br-int
NAME=br-int
DEVICE=br-int
ONBOOT=yes
NETBOOT=yes
TYPE=Ethernet
END

#创建用户，加入公钥
useradd  qycn
mkdir  /home/qycn/.ssh
chmod 700 /home/qycn/.ssh
cat <<END>> /home/qycn/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqamc0opbfXQrwl0K5paqE3DUhXs+ZvFxwIYfo3VQipk8IEu3hfsKsPucQ2f1ja7NPyI4+vzGVFJ1uRosOFU1ce5W8dL7fXksdBjUY2LwQ1LnVFApIWkEDcBvNKTDmyD6qBRK2NOrcymHgOzZIpYbqo4TmkmPqp7Lya6XUG6BbNWj7Q0izVJ29TwQj0WUrdG593I/4sw5gITzSaoYMWmLwcw197okNlyU7LeWLzJ5DltsSWoNXkBcktOPmKLC3QcmM3Me1T+vK1bCp10sGuU7MjAQzfWkongspNUy6+5ZGfPvk33fzrHHVzs0JdYfCuNKR/5/7kSQPg0uKt/DCUvijw== jumpserver@kvmbl.qycn.com
END
chmod  600 /home/qycn/.ssh/authorized_keys
chown qycn:qycn /home/qycn/.ssh/authorized_keys
chown qycn:qycn /home/qycn/.ssh

cat /etc/sudoers|grep -w QYCN
if [ $? -ne 0 ]; then
    echo "Cmnd_Alias QYCN = ALL" >>/etc/sudoers
    echo "qycn ALL = (root)  NOPASSWD: QYCN"  >>/etc/sudoers
fi




echo "安装策略组环境"

firewall-cmd --list-all | grep 'masquerade: no'
if [ $? -ne 1 ]; then
cat /etc/rc.d/rc.local|grep br_netfilte
if [ $? -ne 0 ]; then
echo "/usr/sbin/modprobe br_netfilte"  >>/etc/rc.d/rc.local
fi
/usr/sbin/modprobe br_netfilter
cat /etc/sysctl.conf|grep net.bridge.bridge-nf-call-iptables
if [ $? -ne 0 ]; then
echo "net.bridge.bridge-nf-call-iptables = 1"  >> /etc/sysctl.conf
fi
/usr/sbin/sysctl -p
firewall-cmd  --direct --add-chain ipv4 filter permit
firewall-cmd  --direct --add-chain ipv4 filter default
firewall-cmd  --direct --add-rule ipv4 filter FORWARD 100 -j default
firewall-cmd  --direct --add-rule ipv4 filter FORWARD 99  -j permit
firewall-cmd  --direct --add-rule ipv4 filter default 100  -j ACCEPT
firewall-cmd --permanent --direct --add-chain ipv4 filter permit
firewall-cmd --permanent --direct --add-chain ipv4 filter default
firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 100 -j default
firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 99  -j permit
firewall-cmd --permanent --direct --add-rule ipv4 filter default 100  -j ACCEPT
wget -P /home/tools/ -N 121.201.101.171/secure.py
else echo "出错，防火墙masquerade: yes"
fi


echo "设置sasl密码...... QyKvm20160321!$ "
echo -e ${virt_password}"\n"${virt_password}|saslpasswd2 -c -p -a libvirt kvmadmin
echo -e 'yisu.com\nyisu.com'|passwd root

echo "修改ssh"

sed -i "s@#ClientAliveInterval 0@ClientAliveInterval 60@g"  /etc/ssh/sshd_config
sed -i "s@#ClientAliveCountMax 3@ClientAliveCountMax 3@g"  /etc/ssh/sshd_config
sed -i "s@.*UseDNS.*@UseDNS no@g"  /etc/ssh/sshd_config
sed -i "s@.*GSSAPIAuthentication.*@GSSAPIAuthentication no@g"  /etc/ssh/sshd_config

systemctl restart sshd


echo "下载MegaCli64"
wget -P  /home/tools/  http://117.48.234.190:4000/MegaCli8.02.21.tar.gz
cd /home/tools
tar -zxf MegaCli8.02.21.tar.gz
cd MegaCli8.02.21
rpm -ivh Lib_Utils-1.00-09.noarch.rpm > /dev/null
rpm -ivh MegaCli-8.02.21-1.noarch.rpm > /dev/null
ln -sf /opt/MegaRAID/MegaCli/MegaCli64 /bin/megacli
megacli -LDSetProp WB -Lall -aall   > /dev/null
megacli -LDSetProp CachedBadBBU -Lall -aall > /dev/null


echo "下载dominfo"
wget -O /home/tools/dominfo.sh -N 121.201.101.171/dominfo.sh
echo "alias dominfo='sh /home/tools/dominfo.sh'">> /root/.bashrc
wget  -P /home/tools -N 223.111.182.88/mig  >/dev/null 2>&1;chmod a+x /home/tools/mig
wget -P /tmp -N 223.111.182.88/iso
echo "alias mig='bash /home/tools/mig '"  >> /root/.bashrc
wget -O /home/tools/ips_set_node.py -N  121.201.101.171/ips_set_node.py
cd /usr/bin/;wget -N 223.111.182.88/tcpping;chmod 755 tcpping
yum -y install traceroute
wget -P /tmp -N 223.111.182.88/jiedian_api.py
python /tmp/jiedian_api.py
sed -i -r 's/^.*80.*$//g'  /etc/nginx/nginx.conf

echo  "关闭防火墙"
service firewalld stop

echo  "配置虚拟网卡"
cp /etc/sysconfig/network-scripts/ifcfg-em1 /etc/sysconfig/network-scripts/ifcfg-em1.bak
touch /etc/sysconfig/network-scripts/ifcfg-br0 

echo 'BOOTPROTO=static' >> /etc/sysconfig/network-scripts/ifcfg-br0
echo 'DEVICE=br0' >> /etc/sysconfig/network-scripts/ifcfg-br0
echo 'TYPE=Bridge' >> /etc/sysconfig/network-scripts/ifcfg-br0
echo 'NM_CONTROLLED=no' >> /etc/sysconfig/network-scripts/ifcfg-br0
echo 'STP=no' >> /etc/sysconfig/network-scripts/ifcfg-br0
echo IPADDR=$(cat /etc/sysconfig/network-scripts/ifcfg-em1 | grep "IPADDR="|awk -F '=' '{print $2}') >> /etc/sysconfig/network-scripts/ifcfg-br0
echo 'NETMASK=255.255.255.0' >> /etc/sysconfig/network-scripts/ifcfg-br0
echo 'GATEWAY=192.168.2.1' >> /etc/sysconfig/network-scripts/ifcfg-br0
echo 'DNS1=114.114.114.114' >> /etc/sysconfig/network-scripts/ifcfg-br0
echo 'DNS2=8.8.8.8' >> /etc/sysconfig/network-scripts/ifcfg-br0

echo 'ONBOOT=yes' >> /etc/sysconfig/network-scripts/ifcfg-em1 
echo 'NM_CONTROLLED=no' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'BRIDGE=br0' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'DEVICE=em1' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'BOOTPROTO=none' >> /etc/sysconfig/network-scripts/ifcfg-em1

systemctl restart network
echo  "创建云机"
cd /data/kvm
wget -N http://192.168.2.180/yali/yunji/test.qcow2
wget -N http://192.168.2.180/yali/yunji/test0.qcow2
wget -N http://192.168.2.180/yali/yunji/testdata.qcow2
cp   test.qcow2  test1.qcow2
cp   test.qcow2  test2.qcow2
cp   test.qcow2  test3.qcow2
cp   test.qcow2  test4.qcow2
cp   test.qcow2  test5.qcow2
cp   test.qcow2  test6.qcow2
cp   test.qcow2  test7.qcow2
cp   test.qcow2  test8.qcow2
cp   test.qcow2  test9.qcow2
cp   test.qcow2  test10.qcow2
cp   test.qcow2  test11.qcow2
cp   test0.qcow2  test12.qcow2
cp   test0.qcow2  test13.qcow2
cp   test0.qcow2  test14.qcow2



cp   testdata.qcow2  testdata12.qcow2
cp   testdata.qcow2  testdata13.qcow2
cp   testdata.qcow2  testdata14.qcow2

cd /etc/libvirt/qemu

wget -N http://192.168.2.180/yali/yunji/test.xml
wget -N http://192.168.2.180/yali/yunji/test1.xml
wget -N http://192.168.2.180/yali/yunji/test2.xml
wget -N http://192.168.2.180/yali/yunji/test3.xml
wget -N http://192.168.2.180/yali/yunji/test4.xml
wget -N http://192.168.2.180/yali/yunji/test5.xml
wget -N http://192.168.2.180/yali/yunji/test6.xml
wget -N http://192.168.2.180/yali/yunji/test7.xml
wget -N http://192.168.2.180/yali/yunji/test8.xml
wget -N http://192.168.2.180/yali/yunji/test9.xml
wget -N http://192.168.2.180/yali/yunji/test10.xml
wget -N http://192.168.2.180/yali/yunji/test11.xml
wget -N http://192.168.2.180/yali/yunji/test12.xml
wget -N http://192.168.2.180/yali/yunji/test13.xml
wget -N http://192.168.2.180/yali/yunji/test14.xml


virsh define test.xml
virsh define test1.xml
virsh define test2.xml
virsh define test3.xml
virsh define test4.xml
virsh define test5.xml
virsh define test6.xml
virsh define test7.xml
virsh define test8.xml
virsh define test9.xml
virsh define test10.xml
virsh define test11.xml
virsh define test12.xml
virsh define test13.xml
virsh define test14.xml

cd 

echo /finish/
menu
} 


function yunjitest(){

echo  "云机压力测试开启"
virsh start test
virsh start test3
virsh start test4
virsh start test5
virsh start test6
virsh start test7
virsh start test8
virsh start test9
virsh start test10
virsh start test11
virsh start test12
virsh start test13
virsh start test14
screen -S yunji

while :
do
virsh start test1
virsh start test2
sleep 10
virsh destroy test3
virsh destroy test4
sleep 30
virsh start test3
virsh start test4
sleep 10
virsh destroy test1
virsh destroy test2
sleep 30
done

} 

#菜单
function menu1(){
cat << EOF

`echo ' '`
============【专用脚本】===============
|----------------------------------------------|
|    【1】安装常用工具包及压力测试软件         |
|----------------------------------------------|
|    【2】配置IPMI   【3】配置IP到网卡enp1s0f0 |
|----------------------------------------------|
|    【4】全面检测   【7】升级内核             |
|----------------------------------------------|
|    【5】压力测试   【6】查内存报错           |
|----------------------------------------------|
|    【S】关闭系统   【8】配置IP到网卡em1      |
|----------------------------------------------|
|    【q】退出        【r】重启                |
================================================
`echo ' '`
EOF
read -p "请输入对应的数字：" num2
case $num2 in
  1)
  echo "安装常用工具包"
  tools
  ;;
  2)
  echo "配置IPMI"
  IPMI1
  ;;
  3)
  echo "配置IP到网卡enp1s0f0"
  IP1
  ;;
  4)
  echo "全面检测 "
  testing
  ;;
  5)
  echo "压力测试 "
  yali1
  ;;
  6)
  echo "查内存报错 "
  memcheck
  ;;
  7)
  echo "升级内核 "
  kernel
  ;;
  8)
  echo "配置IP到网卡em1 "
  IP
  ;;
  s)
  echo "关闭系统 "
  init 0
  ;;
  r)
  echo "重启 "
  reboot
  ;;
  q)
  exit 0
  ;;
  *)
  menu
esac

}




#配置IP到网卡em1 
function IP1(){
echo '======================配置IP到网卡enp1s0f0========================'
read -p "输入IP地址：(如192.168.2.88)"  IPADDR
read -p "输入网关：(如192.168.2.1 )"  gateway
read -p "输入掩码：(如255.255.255.0 )"  netmask
echo  IP配置中，请稍等 

sed -i "/IPADDR=/d" /etc/sysconfig/network-scripts/ifcfg-enp1s0f0
sed -i "/NETMASK=/d" /etc/sysconfig/network-scripts/ifcfg-enp1s0f0
sed -i "/GATEWAY=/d" /etc/sysconfig/network-scripts/ifcfg-enp1s0f0

echo IPADDR=${IPADDR} >>  /etc/sysconfig/network-scripts/ifcfg-enp1s0f0
echo NETMASK=${netmask} >>  /etc/sysconfig/network-scripts/ifcfg-enp1s0f0
echo GATEWAY=${gateway} >>  /etc/sysconfig/network-scripts/ifcfg-enp1s0f0
echo 
echo   
echo  IP配置完成打印IP信息 
echo '======================================================'
echo IP地址: $(cat /etc/sysconfig/network-scripts/ifcfg-enp1s0f0 | grep "IPADDR="|awk -F '=' '{print $2}'|sed -n '1p')  
echo 子网掩码: $(cat /etc/sysconfig/network-scripts/ifcfg-enp1s0f0 | grep "NETMASK="|awk -F '=' '{print $2}'|sed -n '1p')  
echo 网关: $(cat /etc/sysconfig/network-scripts/ifcfg-enp1s0f0 | grep "GATEWAY="|awk -F '=' '{print $2}'|sed -n '1p')  
echo '======================================================'
 menu
}


#配置IPMI 
function IPMI1(){
echo '======================IPMI设置========================'
read -p "请输入IP："  ipaddr
ipmitool lan set 1 ipsrc static
   		ipmitool lan set 1 ipaddr ${ipaddr}
   		read -p "请输入掩码："  netmask
   		ipmitool lan set 1 netmask ${netmask}
   		read -p "请输入网关："  defgw
   		ipmitool lan set 1 defgw ipaddr ${defgw}
   		ipmitool lan set 1 access on

      echo ' '
    	echo '====================当前IPMI信息======================'
  		echo IPMI管理IP: $(ipmitool lan print 1 |grep "IP Address              :" |awk '{print $4}'|sed -n '1p')
  		echo IPMI掩码: $(ipmitool lan print 1 |grep "Subnet Mask             : " |awk '{print $4}'|sed -n '1p')
  		echo IPMI网关: $(ipmitool lan print 1 |grep "Default Gateway IP      : " |awk '{print $5}'|sed -n '1p')
  		echo '======================================================'
		menu
}



# 开启压力测试
function yali1(){

free2=`free -g | grep "Mem" | awk '{print $2}'`
free1=$[free2*85/100]G

screen -dmS cpu
screen -x -S cpu -p 0 -X stuff "cd /home/tools/cpuburn;./cpuburn\n"

screen -dmS mem
screen -x -S mem -p 0 -X stuff "memtester $free1 1\n"

screen -dmS io
screen -x -S io -p 0 -X stuff "cd /data/;python iotest.py\n"
echo ' '
echo '======压力测试窗口======'
screen -ls
echo -e "\033[32m 正在进行压力测试，请勿关机！\033[0m"

 menu
}


#服务器配置检测
 function testing1(){
 echo '======================全面检测========================'
echo 
echo ========================================
echo 1.获取时间: $(date)
echo ========================================
echo 2.服务器型号: $(dmidecode |grep "Product Name"|awk '{print $3,$4}'|sed -n '1p') "   " SN码: $(dmidecode -s system-serial-number)
echo ========================================
echo 3.BIOS版本号: $(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p') "   " iDrac固件号: $(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')
echo ========================================
echo 4.系统版本: $(cat /etc/redhat-release)
echo ========================================
echo 5.内核版本: $(uname -r  )
echo ========================================
echo 6.CPU型号: $(cat /proc/cpuinfo | grep name | cut -f2 -d: |sed -n '1p') "   " CPU核心数: $(cat /proc/cpuinfo | grep name | cut -f2 -d: |wc -l)
echo ========================================
echo 7.内存容量: $(cat /proc/meminfo | grep "MemTotal:" | awk '{print $2,$3}'|sed -n '1p';free -g | grep "Mem:" | awk '{print $2}') "GB" "   " 内存条数量:DDR4：$(dmidecode|grep -P -A8 "Memory\s+Device"|grep -E 'Memory Device|Size|Locator'|grep -v Range |grep 'GB' | wc -l) 条"   "DDR3:  $(dmidecode|grep -P -A8 "Memory\s+Device"|grep -E 'Memory Device|Size|Locator'|grep -v Range |grep 'MB' | wc -l)条
echo ========================================
echo 8.万兆网卡: $(lspci | grep Ethernet | grep 10-Gigabit | sed -n '1p' | awk '{print $4,$5,$6,$7}') "   " 网口数量: $(lspci | grep Ethernet | grep 10-Gigabit | wc -l)
echo 当前万兆模块状态:$(ip addr | grep 'p1:' | awk '{print $2,$9}' ) "   "$(ip addr | grep 'p2:' | awk '{print $2,$9}' ) 
echo ========================================
sda=`fdisk -l|grep "Disk /dev/sda"`
sdb=`fdisk -l|grep "Disk /dev/sdb"`
echo ========================================
echo 硬盘分区信息:磁盘sda: $(echo ${sda:14:9} "   "磁盘sdb:  ${sdb:14:10})
echo 硬盘数量: $(megacli -pdlist -a0 | grep -E "Slot|Firmware state|Enclosure Device ID|[Ee]rror|Predictive"|egrep "Error|Firmware|Slot"|grep "Number"|wc -l) 个
echo ========================================
echo 9.RAID卡型号: $(megacli -AdpAllInfo -aALL | grep "Product Name    : " | awk -F ':' '{print $2}') "    " RAID卡版本 $(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')
echo  RAID卡信息
raid10=`megacli -LDInfo -Lall -aALL|grep "RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0"`
if [[ $raid10 = "RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0" ]]
then
echo 创建raid 10
else
echo 
fi
raid0=`megacli -LDInfo -Lall -aALL|grep "RAID Level          : Primary-0, Secondary-0, RAID Level Qualifier-0"`
if [[ $raid0 = "RAID Level          : Primary-0, Secondary-0, RAID Level Qualifier-0" ]]
then
echo 创建raid 0 
else
echo 
fi
raid6=`megacli -LDInfo -Lall -aALL|grep "RAID Level          : Primary-6, Secondary-0, RAID Level Qualifier-3"`
if [[ $raid6 = "RAID Level          : Primary-6, Secondary-0, RAID Level Qualifier-3" ]]
then
echo 创建raid 6 
else
echo 
fi
raid1=`megacli -LDInfo -Lall -aALL|grep "RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0"`
if [[ $raid1 = "RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0" ]]
then
echo 创建raid 1 
else
echo 
fi
echo ========================================
echo 10.IP地址: $(cat /etc/sysconfig/network-scripts/ifcfg-enp1s0f0 | grep "IPADDR="|awk -F '=' '{print $2}'|sed -n '1p')  
echo 子网掩码: $(cat /etc/sysconfig/network-scripts/ifcfg-enp1s0f0 | grep "NETMASK="|awk -F '=' '{print $2}'|sed -n '1p')  
echo 网关: $(cat /etc/sysconfig/network-scripts/ifcfg-enp1s0f0 | grep "GATEWAY="|awk -F '=' '{print $2}'|sed -n '1p')  
echo ========================================
echo 11.IPMI管理IP: $(ipmitool lan print 1 |grep "IP Address              :" |awk '{print $4}'|sed -n '1p')
echo IPMI掩码: $(ipmitool lan print 1 |grep "Subnet Mask             : " |awk '{print $4}'|sed -n '1p')
echo IPMI网关: $(ipmitool lan print 1 |grep "Default Gateway IP      : " |awk '{print $5}'|sed -n '1p')
echo ========================================
echo

menu
}



#服务器R620/R620xd菜单
function menu620(){
cat << EOF
-------------------------------
|*********业务机(R620)*********|
-------------------------------
`echo ' '`
========【重装系统发上架专用脚本】===========

|----------------------------------------------|
|      【1】安装常用工具包及压力测试软件       |
|----------------------------------------------|
|      【2】配置IPMI      【3】配置IP到网卡em1 |
|----------------------------------------------|
|      【4】全面检测(可自动升级内核和固件)     |
|----------------------------------------------|
|      【5】压力测试      【6】查内存报错      |
|----------------------------------------------|
|      【S】关闭系统      【r】重启            |
|----------------------------------------------|
|      【q】退出                               |
================================================
`echo ' '`
EOF
read -p "请输入对应的数字：" num2
case $num2 in
  1)
  echo "安装常用工具包"
  tools
  ;;
  2)
  echo "配置IPMI"
  IPMI
  ;;
  3)
  echo "配置IP到网卡em1"
  IP
  ;;
  4)
  echo "全面检测 "
  testing
  test620
  ;;
  5)
  echo "压力测试 "
  yali1
  ;;
  6)
  echo "查内存报错 "
  memcheck
  ;;
  s)
  echo "关闭系统 "
  init 0
  ;;
  r)
  echo "重启 "
  reboot
  ;;
  q)
  exit 0
  ;;
  *)
  menu
esac

}




#服务器R620/R620xd配置检测
function R620test(){
cat << EOF
`echo ' '`

=============================================
|      【1】一键升级固件及内核              |
|-------------------------------------------|
|      【q】退出   【r】返回上一级目录      |
=============================================
`echo ' '`
EOF
read -p "请输入对应的数字：" num5
case $num5 in
  1)
  echo "一键升级固件及内核"
  kernel
  R720iDrac
  H310p
  R620BIOS
  ;;
  r)
  menu
   ;;
  q)
  exit 0
  ;;
  *)
  menu
esac

}



#服务器R620/R620xd  BIOS固件升级    OK
 function R620BIOS(){
Bios720=`dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p'`
if [[ $Bios720 =~ "2.9.0" ]]
then
     echo "BIOS固件已经是2.9.0不用升级"
echo ' '
else
    wget -N http://192.168.2.182/bios/R620/BIOS_W1WJW_LN_2.9.0.BIN
    chmod a+x BIOS_W1WJW_LN_2.9.0.BIN
echo ' '
echo -e "BIOS升级中，升级过程会重启服务器"
echo ' '
expect <<EOF
spawn ./BIOS_W1WJW_LN_2.9.0.BIN
expect "*" { send "q\r" }
set timeout -1
expect "Y/N:" { send "y\r" }
set timeout -1
expect "Y/N:" { send "y\r" }
expect eof
EOF
fi
 }


#服务器R620 RAID卡H310p mini固件升级
 function H310p(){
H310p='megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}''
if [[ $H310p =~ "20.13.3" ]]
then
     echo RAID卡H310P mini 固件号$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，无需要更新
echo ' '
else
echo RAID卡H310P mini 固件号不是最新的，需要更新
    wget -N http://192.168.2.182/bios/R620/SAS-RAID_Firmware_YP0NF_LN_20.13.3-0001_A11.BIN
    chmod a+x SAS-RAID_Firmware_YP0NF_LN_20.13.3-0001_A11.BIN   
echo ' '
echo -e "RAID卡固件升级中，升级过程会重启服务器"
echo ' '
expect <<EOF
spawn ./SAS-RAID_Firmware_YP0NF_LN_20.13.3-0001_A11.BIN
expect "*" { send "q\r" }
set timeout -1
expect "Y/N:" { send "y\r" }
set timeout -1
expect "Y/N:" { send "n\r" }
expect eof
EOF
fi
 }

#R620服务器配置检测
function test620(){
   echo  "当前服务器为R620" 
   `echo ' '`
echo -e "\033[32m ****************************************\033[0m"
echo -e "\033[32m ****************************************\033[0m"
Version1=`dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p'`
if [[ $Version1 =~ "2.9.0" ]]
then
echo 当前BIOS版本是$(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p')，无需要更新 
else
echo -e "\033[32m 当前BIOS版本是$(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p')，需要更新到2.9.0 \033[0m"
fi

iDrac1=`ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p'`
if [[ $iDrac1 =~ "2.65" ]]
then
echo 当前iDrac版本是$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')，无需要更新 
else
echo -e "\033[32m 当前iDrac版本是$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')，需要更新到2.65 \033[0m"
fi

RAID1=`megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}'`
if [[ $RAID1 =~ "20.13.3" ]]
then
echo 当前RAID卡固件号$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，无需要更新 
else
echo -e "\033[32m当前RAID卡固件号$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，需要更新到20.13.3 \033[0m"
fi

uname1=`uname -r`
if [[ $uname1 =~ "4.4.229-1.el7.elrepo.x86_64" ]]
then
echo 当前内核是$(uname -r)，无需要更新 
else
echo -e "\033[32m 内核版本没有更新的，需要更新到4.4.229 \033[0m"
echo '==========================='
fi
echo -e "\033[32m ****************************************\033[0m"
echo -e "\033[32m ****************************************\033[0m"
R620test
}

#服务器C6230菜单
function menu6230(){
cat << EOF
-------------------------------
|*********业务机(C6230)*********|
-------------------------------
`echo ' '`
========【重装系统发上架专用脚本】===========

|----------------------------------------------|
|      【1】安装常用工具包及压力测试软件       |
|----------------------------------------------|
|      【2】配置IPMI      【3】配置IP到网卡em1 |
|----------------------------------------------|
|      【4】全面检测                           |
|----------------------------------------------|
|      【5】压力测试      【6】查内存报错      |
|----------------------------------------------|
|      【S】关闭系统      【r】重启            |
|----------------------------------------------|
|      【q】退出                               |
================================================
`echo ' '`
EOF
read -p "请输入对应的数字：" num2
case $num2 in
  1)
  echo "安装常用工具包"
  tools
  ;;
  2)
  echo "配置IPMI"
  IPMI
  ;;
  3)
  echo "配置IP到网卡em1"
  IP
  ;;
  4)
  echo "全面检测 "
  testing
  menu6230
  ;;
  5)
  echo "压力测试 "
  yali1
  ;;
  6)
  echo "查内存报错 "
  memcheck
  ;;
  s)
  echo "关闭系统 "
  init 0
  ;;
  r)
  echo "重启 "
  reboot
  ;;
  q)
  exit 0
  ;;
  *)
  menu
esac

}

#服务器R630/R630xd配置检测
function R630test(){
cat << EOF
`echo ' '`

=============================================
|      【1】一键升级固件及内核              |
|-------------------------------------------|
|      【q】退出   【r】返回上一级目录      |
=============================================
`echo ' '`
EOF
read -p "请输入对应的数字：" num5
case $num5 in
  1)
  echo "一键升级固件及内核"
  kernel
  R730iDrac
  R730RAID
  R730BIOS
  ;;
  r)
  menu
   ;;
  q)
  exit 0
  ;;
  *)
  menu
esac

}



#服务器R620/R620xd菜单
function menu630(){
cat << EOF
-------------------------------
|*********业务机(R630)*********|
-------------------------------
`echo ' '`
========【重装系统发上架专用脚本】===========

|----------------------------------------------|
|      【1】安装常用工具包及压力测试软件       |
|----------------------------------------------|
|      【2】配置IPMI      【3】配置IP到网卡em1 |
|----------------------------------------------|
|      【4】全面检测(可自动升级内核和固件)     |
|----------------------------------------------|
|      【5】压力测试      【6】查内存报错      |
|----------------------------------------------|
|      【S】关闭系统      【r】重启            |
|----------------------------------------------|
|      【q】退出                               |
================================================
`echo ' '`
EOF
read -p "请输入对应的数字：" num2
case $num2 in
  1)
  echo "安装常用工具包"
  tools
  ;;
  2)
  echo "配置IPMI"
  IPMI
  ;;
  3)
  echo "配置IP到网卡em1"
  IP
  ;;
  4)
  echo "全面检测 "
  testing
  test630
  ;;
  5)
  echo "压力测试 "
  yali1
  ;;
  6)
  echo "查内存报错 "
  memcheck
  ;;
  s)
  echo "关闭系统 "
  init 0
  ;;
  r)
  echo "重启 "
  reboot
  ;;
  q)
  exit 0
  ;;
  *)
  menu
esac

}


#R630服务器配置检测
function test630(){
   echo  "当前服务器为R630" 
   `echo ' '`
echo -e "\033[32m ****************************************\033[0m"
echo -e "\033[32m ****************************************\033[0m"
Version1=`dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p'`
if [[ $Version1 =~ "2.11.0" ]]
then
echo 当前BIOS版本是$(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p')，无需要更新 
else
echo -e "\033[32m 当前BIOS版本是$(dmidecode |grep "Version: "|awk '{print $2}'|sed -n '1p')，需要更新到2.11.0 \033[0m"
fi

iDrac1=`ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p'`
if [[ $iDrac1 =~ "2.75" ]]
then
echo 当前iDrac版本是$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')，无需要更新 
else
echo -e "\033[32m 当前iDrac版本是$(ipmitool mc info | grep "Firmware Revision         :"|awk '{print $4}'|sed -n '1p')，需要更新到2.75 \033[0m"
fi

RAID1=`megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}'`
if [[ $RAID1 =~ "25.5.8" ]]
then
echo 当前RAID卡固件号$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，无需要更新 
else
echo -e "\033[32m当前RAID卡固件号$(megacli -AdpAllInfo -aALL | grep "FW Package Build:" | awk -F ':' '{print $2}')，需要更新到25.5.8 \033[0m"
fi

uname1=`uname -r`
if [[ $uname1 =~ "4.4.229-1.el7.elrepo.x86_64" ]]
then
echo 当前内核是$(uname -r)，无需要更新 
else
echo -e "\033[32m 内核版本没有更新的，需要更新到4.4.229 \033[0m"
echo '==========================='
fi
echo -e "\033[32m ****************************************\033[0m"
echo -e "\033[32m ****************************************\033[0m"
R630test
}

menu